<form action='index.php?input&action=inputProvider' 
	method='post' enctype='multipart/form-data' id='frmInputProvider'>
	<fieldset class="form">
    	<ol>
        	<li class="input">
            	<label for="name">Tên Địa Điểm</label>
                <input type="text" class="txt_full" name="txtProviderName" />
            </li>
            <li class="input">
            	<label for="mota">Mô Tả</label>
                <br />
                <textarea id="diadiem_input" class="textarea_input" rows="5" cols="60" name="txtProviderDes"></textarea>				
			</li>
            <li class="input">
            	<label for="thanhpho">Thành phố</label>
				<select class="txt_full" id="selCity" name="selCity">                                    	
                </select>
            </li>
            <li class="input">
            	<label for="quan">Quận/Huyện</label>
                <select class="txt_full" id="selDistrict" name="selDistrict">
                </select>
			</li>
            <li class="input">
            	<label for="phuong">Phường/Xã</label>
                <select class="txt_full" id="selWard" name="selWard">
                </select>
			</li>        
            <li class="input">  
            	<label for="sonha">Số Nhà</label>
                <input type="text" class="txt_short" name="txtNumber" />
            </li>
            <li class="input">        
            	<label for="duong">Đường</label>
				<input type="text" class="txt_full" name="txtStreet" />
            </li>      
            <li class="input">        
            	<label for="website">Website</label>
				<input type="text" class="txt_full" name="txtWebsite" />
            </li>
            <li class="input">
            	<label for="cellphone">ĐT di động</label>
                <input type="text" class="txt_full" name="txtCellphone" />
            </li>
            <li class="input">
            	<label for="telephone">ĐT cố định</label>
                <input type="text" class="txt_full" name="txtTelephone" />
            </li>                                                          
            <li class="input">
            	<label for="hinhanh">Hình Ảnh</label>
				<input type="file" name="imgProvider" id="imgProvider" />
            </li>  
            <li>
            	<label for="phanloai">Phân Loại</label>
            	<input type="hidden" name="categoryProviderList" />
                <div style="display:inline-block">
                	<table id="tblCatProvider">
                    	<tr>
                        	<td>
                                <select name="selCatProvider1" id="selCatProvider1">
                                	<?php
                                		$catProvider =  $arrCatProvider1[0];
                                	?>
                                	<option selected="selected" value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
                                	<?php                 
                                	    for ($i = 1; $i < count($arrCatProvider1); $i++) {
                                			$catProvider = $arrCatProvider1[$i];                                	
                                	?>
                                	<option value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
                                	<?php 		
                                		} 
                                	?>	
                                </select>
                            </td>
                            <td>
                                <select name="selCatProvider2" id="selCatProvider2">
                                    <?php
                                		$catProvider =  $arrCatProvider2[0];
                                	?>
                                	<option selected="selected" value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
                                	<?php                 
                                	    for ($i = 1; $i < count($arrCatProvider2); $i++) {
                                			$catProvider = $arrCatProvider2[$i];                                	
                                	?>
                                	<option value="<?php echo $catProvider->getCategoryID();?>"><?php echo $catProvider->getCategory();?></option>
                                	<?php 		
                                		} 
                                	?>                            	
	                            </select>
                            </td>
                            <td><input type="button" id="lnkAddProviderCategory" value="Thêm" /></td>                            
						</tr>                                		                                		
					</table>
	            </div>
    		</li>   
            <li class="input">
            	<label for="danhgia">Đánh Giá</label>                                    
                <div style="display:inline-block;" id='blockDanhGia'>
                	<input type="button" id="btnDanhGiaProvider" value="Thực hiện đánh giá" />
                    <input type="hidden" name="answerList" />
                </div>                                                                        
            </li>  					                                                                    
		</ol>
	</fieldset>
    <div class="searchBt"><input type="submit" value="Xong Rùi" /></div>
</form>
<div class="clear"></div>

<div id="dlgDanhGiaProvider" title="Đánh Giá">
	<form name="frmDanhGiaProvider">
		<div id="contentDanhGiaProvider">
		</div>
		<input type="button" value="Đồng Ý" id="btnDongYDanhGiaProvider" /> 
		<input type="button" value="Thoát" id="btnThoatDanhGiaProvider" />
	</form>
</div>

<script language="javascript">
	$('#diadiem_input').wysiwyg();
		
	$('#dlgDanhGiaProvider').dialog({autoOpen: false, width:'360px'});
	$('input[name=categoryProviderList][type=hidden]').val('');
	$('#frmInputProvider input[name=answerList]').val('');
	
	$('#btnThoatDanhGiaProvider').click(function() {		
		$('#dlgDanhGiaProvider').dialog('close');
	});
			
	$('#btnDongYDanhGiaProvider').click(function(){		
		var str = $.getDanhGiaProvider();		
		$('#frmInputProvider input[name=answerList]').val(str);
		alert(str);		
		$('#dlgDanhGiaProvider').dialog('close');
	});	

	$('#lnkAddProviderCategory').click(function() {				
		var val = $('#selCatProvider2 option:selected').val();
		var newRow = '<tr><td>' + $('#selCatProvider1 option:selected').html() + '</td>' 
			+ '<td>' + $('#selCatProvider2 option:selected').html() + '</td>' 
			+ '<td>' + '<input type="button" value="Xóa" onclick="$.removeRow(this)"></td>'
			+ '<td><input type="hidden" class="hiddenCatProviderID" value="' + val + '" /></td>' 
			+'</tr>';
		$('#tblCatProvider tr:last').after(newRow);

		/*var str = $('input[name=categoryProviderList][type=hidden]').val();
		str += ' ' + $('#selCatProvider2 option:selected').val();
		$('input[name=categoryProviderList][type=hidden]').val(str);*/
	});	
	
	var url = 'index.php?location&action=get';
	var pid = 0;			
	$.post(url, 
		{parentID: pid}, 
		function(xml) {			
			var str1 = $.getXMLStringOf(xml, 'location');
			if (str1 != '') {
				$('#selCity').html(str1);
				pid = $('#selCity option:selected').val();						
				$.post(url, 
					{parentID: pid}, 
					function(xml) {								
						var str2 = $.getXMLStringOf(xml, 'location');								
						if (str2 != '') {
							$('#selDistrict').html(str2);
							pid = $('#selDistrict option:selected').val();
							$.doPostGetLocationList(pid, '#selWard', url);
						}
					}
				);
			} 												
		}
	);
	
	$('#selCity').change(function() {
		url = 'index.php?location&action=get';
		var pid = $('#selCity').val(); 
		$.post(url, 
			{parentID: pid}, 
			function(xml) {
				var str = $.getXMLStringOf(xml, 'location');
				$('#selDistrict').html(str);

				var pid = $('#selDistrict').val();
				$.doPostGetLocationList(pid, '#selWard', url);
			}
		);
	});

	$('#frmInputProvider').submit(function() {
		var str = '';
		if ($('#frmInputProvider [name=txtProviderName]').val() == '') {			
			str += 'Bạn chưa nhập tên provider\n';
		}
		if ($('#frmInputProvider [name=txtNumber]').val() == '') {
			str += 'Bạn chưa nhập số nhà\n';
		}
		if ($('#frmInputProvider [name=txtStreet]').val() == '') {
			str += 'Bạn chưa nhập số nhà\n';
		}	
		if ($('#imgProvider').val() == '') {
			str += 'Bạn chưa upload hình ảnh\n';			
		} 

		if (str != '') {
			alert(str);
			return false;
		}	

		var str = '';
		$('input[class=hiddenCatProviderID]').each(function(index) {
			str += ' ' + $(this).val();		    
		});		
		$('input[name=categoryProviderList][type=hidden]').val(str);
		
		return true;
	});
	
	$('#selDistrict').change(function() {				
		url = 'index.php?location&action=get';
		var pid = $('#selDistrict').val();
		$.doPostGetLocationList(pid, '#selWard', url);
	});

	$('#selCatProvider1').change(function() {
		pid = $('#selCatProvider1 option:selected').val();
		url = 'index.php?input&action=getCategoryProvider';

		$.doPostGetCategoryList(pid, '#selCatProvider2', url);				
	});	
</script>